/**
 * 
 */
package de.fsujena.chat_pi.client;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;

import de.fsujena.chat_pi.connection.RSAException;
import de.fsujena.chat_pi.ressources.User;
import de.fsujena.chat_pi.ressources.Room;
import de.fsujena.chat_pi.ressources.message.TextMessage;
import de.fsujena.chat_pi.ressources.message.SysMessage.CATEGORY;
import de.fsujena.chat_pi.ressources.message.SysMessage.MESSAGE;
import de.fsujena.chat_pi.client.userInterface.GraphicalUI;

/**
 * @author dave
 * 
 *
 */
public class Worker {
	public Client clientObject;
	public boolean want_on_whitelist=false;
	public String want_on_whitelist_name;
	public List<String> want_on_whitelist_dir=new ArrayList<String>();
	
	
	
	public Worker(Client clientObject){
		this.clientObject=clientObject;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	/**
	 * start connectionthread which connects to the server
	 * @param ip the ipadress of the server
	 * @param port	the port on which the server is running
	 */
	public void connect(String ip, int port) {

		try {
			clientObject.connectionThread = new ConnectionThread(ip, port,clientObject);		//create new thread
		} catch (IOException e1) {												//error on connecting?
			// e1.printStackTrace();
			clientObject.isconnected = false;									//flag as not connected
			showStatus();														//show that to the user
			clientObject.UI.postError("couldn't connect to server");						//show it again
			//e1.printStackTrace();					
			return;
		} catch (RSAException e) {
			//e.printStackTrace();
			clientObject.UI.postError("problem occured while setting up RSA encryption");
		}
		clientObject.isconnected = clientObject.connectionThread.server.isConnected();		//flag as connected 

		if (!clientObject.isconnected) {													//show the status of the connection
			showStatus();
			return;
		}
		clientObject.connectionThread.start();												//starts the thread
		clientObject.connectionThread.mainThread = clientObject;							//give him the reference to the main thread

		return;
	}
	/**
	 * Initialize the registration process
	 * @param name username to register
	 * @param pass the password of the user
	 */
	public void register(String name, String pass) {
		if(clientObject.isconnected==true){
		clientObject.connectionThread.sendSysMessage(CATEGORY.REGISTRATION, MESSAGE.WANT_TO_REGISTER);	//tell the server that you want to register a new user

		clientObject.username = name;													//save username for later use
		clientObject.password = pass;													//save password for later use

		clientObject.connectionThread.username = name;									//save username for later use
		clientObject.connectionThread.password = pass;									//save password for later use
		}else{
			clientObject.UI.postError("not connected to server couldn't register");
		}
		return;
	}
	/**
	 * Initialize the login process
	 * @param name username to login
	 * @param pass password of the user		
	 */
	public void login(String name, String pass) {
		if(clientObject.isconnected==true){
		clientObject.connectionThread.sendSysMessage(CATEGORY.LOGIN, MESSAGE.WANT_TO_LOGIN);	//tell the server that you want to login

		clientObject.username = name;										//save username for later use
		clientObject.password = pass;										//save password for later use

		clientObject.connectionThread.username = name;						//save username for later use
		clientObject.connectionThread.password = pass;						//save password for later use
		}else{
			clientObject.UI.postError("not connected to server couldn't log in");
		}
		return;
	}
	/**
	 * changes the name of the user
	 * @param name new username
	 */
	public void changeName(String name){
		clientObject.connectionThread.sendSysMessage(CATEGORY.CHANGE_USERNAME,MESSAGE.WANT_TO_CHANGE_USERNAME);	//tell the server that you want to change your name
		clientObject.newusername=name;																			//save the new name
		clientObject.connectionThread.newusername=name;
		return;
	}
	/**
	 * changes the password of the user
	 * @param pass	the new password
	 */
	public void changePassword(String pass){
		clientObject.connectionThread.sendSysMessage(CATEGORY.CHANGE_PASSWORD,MESSAGE.WANT_TO_CHANGE_PASSWORD);	//tell the server that you want to change the password
		clientObject.newpassword=pass;																			//save new password
		clientObject.connectionThread.newpassword=pass;
		return;
	}
	
	/**
	 * show help text
	 * 
	 * @throws IOException
	 */
	public void showHelp() {

		File file = new File("help.txt");
		List<String> line = new ArrayList<String>();
		if (file.exists()) {
			try {

				BufferedReader reader = null;
				reader = new BufferedReader(new FileReader(file));
				String s = null;

				while ((s = reader.readLine()) != null) {
					line.add(s);
				}

				if (reader != null) {
					reader.close();
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else
			clientObject.UI.postError("helpfile missing");
		for (int i = 0; i < line.size(); i++)
			clientObject.UI.postText(line.get(i));

		return;
	}

	/**
	 *show the status of the connection 
	 */
	public void showStatus() {

		if ((clientObject.connectionThread != null) && (clientObject.connectionThread.server != null)) {		//control if connectionthread and server socket exists(could throw null pointer exception otherwise)
			clientObject.isconnected = clientObject.connectionThread.server.isConnected();						//get state of connection
		} else
			clientObject.isconnected = false;																	//if thread doesn't exists flag as not connected
		if (clientObject.isconnected == true) {																	//if connected
			clientObject.UI.postInfo("connected to server " + clientObject.ipadress + " on port:"		//tell that the user
					+ clientObject.port + "\n");
			if(clientObject.connectionThread.loggedIn){															//if logged in
				clientObject.UI.postInfo("you are logged in as "+clientObject.connectionThread.username);//tell the user
				clientObject.connectionThread.sendSysMessage(CATEGORY.STATUS,MESSAGE.REQUEST_ROLE);				//and request role
			}else{
				clientObject.UI.postInfo("you are not logged in");
			}
		} else {
			clientObject.UI.postInfo("not connected to server");											//if not 
			clientObject.UI.postInfo("type '$ help' to see commands \n");								//tell them
		}
		return;
	}

	/**
	 * tells the server that you want to logout
	 */
	public void logout() {
		clientObject.connectionThread.sendSysMessage(CATEGORY.LOGIN, MESSAGE.LOGGED_OUT, clientObject.username);	//tells the server that user "username" wants to logout
		clientObject.connectionThread.loggedIn=false;																//flag as logged out
		return;
	}

	/**
	 * disconnect from the server
	 */
	public void disconnect() {
		clientObject.connectionThread.sendSysMessage(CATEGORY.CONNECTION, MESSAGE.DISCONNECTED, clientObject.username);		//tell the server that your are going to disconnect
		if (clientObject.connectionThread != null){												
			clientObject.connectionThread.loggedIn=false;
			clientObject.connectionThread.disconnect();											//disconnect
			clientObject.connectionThread=null;													//free resources
		}
		clientObject.UI.postInfo("you disconnected from the server");
		clientObject.isconnected = false;														//flag as disconnected
		if(clientObject.UI instanceof GraphicalUI){
			User nulluser=null;
			Room temproom=new Room("Foyer",null,0,nulluser);
			((GraphicalUI)clientObject.UI).updateRoomTree(temproom);
		}
		return;
	}
	/**
	 * prints the history to the screen
	 */
	public void showHistory(){
		loadHistory();
		if(clientObject.msgArray!=null){															
		for(int i=0;i<clientObject.msgArray.size();i++){											//loop through all messages
			clientObject.UI.postText(clientObject.msgArray.get(i));
			}
		}	
		}
		
	
	/**
	 * removes the history file
	 */
	public void removeHistory(){
		String relativpath;
		try {
			relativpath = new File(".").getCanonicalPath();				//get the relative path
			String filename=relativpath+File.separatorChar+"history"+File.separatorChar+clientObject.connectionThread.username+".dat";	//create filepath for the history
			File file=new File(filename);
			file.delete();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		return;
	}
	/**
	 * rename the history 
	 * @param newname new name of the user
	 */
	public void renameHistory(String newname){
		String relativpath;
		try {
			relativpath = new File(".").getCanonicalPath();
			
		String filename=relativpath+File.separatorChar+"history"+File.separatorChar+clientObject.connectionThread.username+".dat";
		File file=new File(filename);
		String newfilename="history"+File.separatorChar+newname+".dat";
		File newfile=new File(newfilename);
		file.renameTo(newfile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return;
	}
	/**
	 * save the history to a file
	 */
	public void saveHistory(){
		
		
		try {
			String relativpath=new File(".").getCanonicalPath();
			new File(relativpath+File.separatorChar+"history").mkdir();
			String filename=relativpath+File.separatorChar+"history"+File.separatorChar+clientObject.connectionThread.username+".dat";
			File file=new File(filename);
			FileOutputStream f;
			ObjectOutputStream s;
			f = new FileOutputStream(file);
			s = new ObjectOutputStream(f);
			s.writeObject(clientObject.msgArray);
			s.close();
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
			
		} catch (IOException e) {
			e.printStackTrace();
			
		}
		
		
		
		return;
	}
	/**
	 * loads history from file
	 */
	@SuppressWarnings("unchecked")
	public void loadHistory(){
		
		try {
			String relativpath=new File(".").getCanonicalPath();
			String filename=relativpath+File.separatorChar+"history"+File.separatorChar+clientObject.connectionThread.username+".dat";
			File file=new File(filename);
			file.createNewFile();
			if(file.exists()){
				FileInputStream f = new FileInputStream(file);
			ObjectInputStream s = new ObjectInputStream(f);
			Object inputObject = s.readObject();
			
			if (inputObject instanceof List<?>)
				clientObject.msgArray = (List<String>) inputObject;
			
			s.close();
			}
		} catch (IOException e) {
			//e.printStackTrace();
		} catch (ClassNotFoundException e) {
			//e.printStackTrace();
		}
		
		return;
	}
	public void changeRoom(List<String> dir){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.WANT_TO_ENTER_ROOM, null, dir);
		return;
	}
	
	public void createRoom(List<String> dir){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.CREATE_ROOM, null, dir);
		return;
	}
	
	public void deleteRoom(List<String> dir){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REMOVE_ROOM, null, dir);
		return;
	}
	
	/**
	 * evaluates the userinput
	 * @param command string containing userinput
	 */
	public void commander(String command) {
		
		String[] arg = command.split(" "); 					//splits input on every " " (arg[0] should contain"$")
		if (arg.length>=2){
		if ((arg[1].equals("connect"))) {					//if command is connect start connecting to server
			if (arg.length == 3) {							//length have to be 3 because it consists of $+connect+"ip:port"
				String[] arg2 = arg[2].split(":");			//Separate ip and port
				if (arg2.length == 2) {						//length should be 2
					clientObject.ipadress = arg2[0];
					try {
						clientObject.port = Integer.parseInt(arg2[1]);	//converts port-string into integer
					} catch (NumberFormatException e) {			
						// e.printStackTrace();
						clientObject.UI.postError("invalid port");						//on exception show error
						showStatus();
						return;
					}

					connect(clientObject.ipadress, clientObject.port);				//connect to server
				} else
					clientObject.UI.postError("invalid number of parameters");								//show error if number of parameter didn't match
			} else
				clientObject.UI.postError("invalid number of parameters");									//show error if number of parameter didn't match
		} else if (arg[1].equals("disconnect"))		
			disconnect();												//disconnect from the server
		else if (arg[1].equals("status"))
			showStatus();												//give the state of the connection
		else if (arg[1].equals("help"))
			showHelp();													//open help
		else if (arg[1].equals("exit"))
			clientObject.killClient();														//stop client
		else if (arg[1].equals("login"))													//log in server
			if (arg.length == 4)															//check number of arguments
				clientObject.worker.login(arg[2], arg[3]);
			else
				clientObject.UI.postError("invalid number of parameters");									//invalid number of arguments
		else if (arg[1].equals("register"))
			if (arg.length == 4)															//check number of arguments
				clientObject.worker.register(arg[2], arg[3]);								//register on the server
			else
				clientObject.UI.postError("invalid number of parameters");									//ect.
		else if (arg[1].equals("userlist"))
			clientObject.connectionThread.sendSysMessage(CATEGORY.STATUS, MESSAGE.REQUEST_USER_LIST);	//request userlist
		else if (arg[1].equals("logout"))								//log out
			logout();
		else if(arg[1].equals("change")&&arg[2].equals("username"))		//change username
			if (arg.length == 4)
				changeName(arg[3]);
			else
				clientObject.UI.postError("invalid number of parameters");		
		else if(arg[1].equals("change")&&arg[2].equals("password"))		//change password
			if (arg.length == 4)
				clientObject.worker.changePassword(arg[3]);
			else
				clientObject.UI.postError("invalid number of parameters");
		else if(arg[1].equals("remove")&&arg[2].equals("user")) 										//remove an user from the list
			clientObject.connectionThread.sendSysMessage(CATEGORY.ADMIN,MESSAGE.REMOVE_USER,arg[3]);
		else if(arg[1].equals("kick")&&arg[2].equals("user")) 											//kick an user
			clientObject.connectionThread.sendSysMessage(CATEGORY.MODERATE,MESSAGE.KICK_USER,arg[3]);
		else if(arg[1].equals("bann")&&arg[2].equals("user")) 											//bann an user
			clientObject.connectionThread.sendSysMessage(CATEGORY.MODERATE,MESSAGE.BANN_USER,arg[3]);
		else if(arg[1].equals("unbann")&&arg[2].equals("user")) 										//unbann an user
			clientObject.connectionThread.sendSysMessage(CATEGORY.MODERATE,MESSAGE.UNBANN_USER,arg[3]);		
		else if (arg[1].equals("adminlist"))
			clientObject.connectionThread.sendSysMessage(CATEGORY.STATUS, MESSAGE.REQUEST_ADMIN_LIST);	//request list of admins
		else if (arg[1].equals("modlist"))
			clientObject.connectionThread.sendSysMessage(CATEGORY.STATUS, MESSAGE.REQUEST_MOD_LIST);	//request list of moderators
		else if (arg[1].equals("remove")&&arg[2].equals("me")){											//removes the user from the server list (is no longer registered)
			clientObject.connectionThread.sendSysMessage(CATEGORY.REGISTRATION, MESSAGE.REMOVE_ME);
			removeHistory();
		}
		else if (arg[1].equals("show")&&arg[2].equals("history")){										//shows history
			showHistory();
		}else if (arg[1].equals("delete")&&arg[2].equals("history")){									//deletes history
			removeHistory();
			clientObject.msgArray.clear();
		}else if (arg[1].equals("create")&&arg[2].equals("room")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
			String[] temp=arg[3].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
			clientObject.worker.createRoom(dir);
		}else if (arg[1].equals("enter")&&arg[2].equals("room")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
				dir.add("Foyer");
			String[] temp=arg[3].split("/");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
				clientObject.worker.changeRoom(dir);
		}else if (arg[1].equals("remove")&&arg[2].equals("room")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
				dir.add("Foyer");
			String[] temp=arg[3].split("/");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
				clientObject.worker.deleteRoom(dir);
		}else if (arg[1].equals("rename")&&arg[2].equals("room")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
				dir.add("Foyer");
			String[] temp=arg[3].split("/");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
				clientObject.worker.renameRoom(dir,arg[arg.length-1]);
		}else if (arg[1].equals("show")&&arg[2].equals("room")){
			clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REQUEST_ROOM_DIR);
		
			
		}else if (arg[1].equals("show")&&arg[2].equals("rooms")){
			clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.AVAILABLE_ROOMS,clientObject.connectionThread.username,clientObject.roomDir);
		
		}else if ((arg[1].equals("warn"))&&(arg[2].equals("user"))) {
			if (arg.length>=4) {
				String temp="";
				for(int i=4;i<arg.length;i++){
					temp=temp+arg[i]+" ";
				}
				warnUser(arg[3],temp);
			} else {
				clientObject.UI.postError("invalid number of arguments");
			}
		}else if (arg[1].equals("create")&&arg[2].equals("private")&&arg[3].equals("room")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>4){
			String[] temp=arg[4].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
			clientObject.worker.createPrivateRoom(dir);
		}else if (arg[1].equals("add")&&arg[2].equals("user")&&arg[3].equals("to")&&arg[4].equals("whitelist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>6){
			String[] temp=arg[6].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			if (arg.length>5){
			this.addUserToWhitelist(dir,arg[5]);
			}else{
				this.clientObject.UI.postError("invalid number of arguments");
			}
						
		}else if (arg[1].equals("remove")&&arg[2].equals("user")&&arg[3].equals("from")&&arg[4].equals("whitelist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>6){
			String[] temp=arg[6].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			if (arg.length>5){
			this.removeUserFromWhitelist(dir,arg[5]);
			}else{
				this.clientObject.UI.postError("invalid number of arguments");
			}
						
		}else if (arg[1].equals("add")&&arg[2].equals("user")&&arg[3].equals("to")&&arg[4].equals("blacklist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>6){
			String[] temp=arg[6].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}			
			if (arg.length>5){
			this.addUserToBlacklist(dir,arg[5]);
			}else{
				this.clientObject.UI.postError("invalid number of arguments");
			}
						
		}else if (arg[1].equals("remove")&&arg[2].equals("user")&&arg[3].equals("from")&&arg[4].equals("blacklist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>6){
			String[] temp=arg[6].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}			
			if (arg.length>5){
			this.removeUserFromBlacklist(dir,arg[5]);
			}else{
				this.clientObject.UI.postError("invalid number of arguments");
			}
						
		}else if (arg[1].equals("request")&&arg[2].equals("whitelist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
			String[] temp=arg[3].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			this.requestWhitelist(dir);
						
		}else if (arg[1].equals("request")&&arg[2].equals("blacklist")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>3){
			String[] temp=arg[3].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			this.requestBlacklist(dir);
						
		}else if (arg[1].equals("whisper")&&arg[2].equals("to")){
			String msg="";
			for(int i=4; i<arg.length;i++){
				msg=msg+arg[i]+"";
			}
			this.whisper(arg[3], msg);
							
		}else if(arg[1].equals("make")&&arg[2].equals("room")&&arg[3].equals("public")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>4){
			String[] temp=arg[4].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
			this.makeRoomPublic(dir);
		}else if(arg[1].equals("make")&&arg[2].equals("room")&&arg[3].equals("private")){
			List<String> dir=new ArrayList<String>();
			dir.clear();
			if (arg.length>4){
			String[] temp=arg[4].split("/");
			dir.add("Foyer");
			for(int i=0;i<temp.length;i++){
				dir.add(temp[i]);
			}
			}
			
			this.makeRoomPrivate(dir);
			
		
			clientObject.UI.postError("invalid command type $ help to see a list off commands");	//no valid command
		return;
		}
		}else if(arg[1].equals("yes")){
			if(this.want_on_whitelist){
				want_on_whitelist_accept();
			}else{
				clientObject.UI.postError("yes what?");
			}
		}else if(arg[1].equals("no")){
			if(this.want_on_whitelist){
				want_on_whitelist_denied();
			}else{
				clientObject.UI.postError("no what?");
			}
		}else{
		clientObject.UI.postError("invalid command type $ help to see a list off commands");		//no valid command
		return;
	}
	}
	
	public void warnUser(String user,String reason){
		clientObject.connectionThread.sendSysMessage(CATEGORY.MODERATE,MESSAGE.USER_WARNING,user,reason);
	}

	
	public void createPrivateRoom(List<String> dir){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.CREATE_PRIVATE_ROOM, null, dir);
	}
	
	public void addUserToWhitelist(List<String> dir,String name){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.ADD_TO_WHITELIST, name,dir);
		
	}
	public void removeUserFromWhitelist(List<String> dir,String name){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REMOVE_FROM_WHITELIST, name,dir);	
	}
	public void addUserToBlacklist(List<String> dir,String name){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.ADD_TO_BLACKLIST, name,dir);
	}
	public void removeUserFromBlacklist(List<String> dir,String name){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REMOVE_FROM_BLACKLIST, name,dir);
	}
	public void requestWhitelist(List<String> dir){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REQUEST_WHITELIST,null,dir);
	}
	public void requestBlacklist(List<String> dir){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.REQUEST_BLACKLIST,null,dir);
	}
	public void whisper(String name,String message){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.MISCELLANEOUS, MESSAGE.WHISPER, name, message);
	}
	public void makeRoomPublic(List<String> dir){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.MAKE_PUBLIC,null,dir);
	}
	public void makeRoomPrivate(List<String> dir){
		this.clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.MAKE_PRIVATE,null,dir);
	}
	public void want_on_whitelist_accept(){
		this.addUserToWhitelist(this.want_on_whitelist_dir, this.want_on_whitelist_name);
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.WANT_ON_WHITELIST_ACCEPTED, this.want_on_whitelist_name, this.want_on_whitelist_dir);
		this.want_on_whitelist=false;
		this.want_on_whitelist_name="";
		this.want_on_whitelist_dir.clear();
	}
	public void want_on_whitelist_denied(){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.WANT_ON_WHITELIST_DENIED, this.want_on_whitelist_name, this.want_on_whitelist_dir);
		this.want_on_whitelist=false;
		this.want_on_whitelist_name="";
		this.want_on_whitelist_dir.clear();
	}
	public void renameRoom(List<String> dir,String newname){
		clientObject.connectionThread.sendSysMessage(CATEGORY.ROOMMANAGEMENT, MESSAGE.RENAME_ROOM,newname,dir);
	}
}
